#coding=utf-8
import random
import time

skls=["哉佩利敖光线","须佐能乎","十万伏特","焰分噬浪尺","我眼即你眼","蓝银霸皇枪","回复","无下限术式","超电磁炮","咒力拳","雷切"]
tls=["狂暴","灵巧","盾山","铁腕"]
tlexps=["额外伤害","闪避概率增加","被暴击时部分伤害减免","额外生命值"]
xuzuoa=False
zaiyana=False
wuxiana=False
xuzuob=False
zaiyanb=False
wuxianb=False

totalAttacka=0
totalAttackb=0
totalTreatmenta=0
totalTreatmentb=0
cnt=0
add=0
adda=0
addb=0

#############################################定义随机函数
try:
    def doRandint(sd,bg,ed,c):

        random.seed(sd*c+time.time())
        return random.randint(bg,ed)

    def doRandomChoice(sd,lst,c):

        random.seed(sd*c+time.time())
        return random.choice(lst)

    def doRandomHide(sd,c):

        random.seed(sd*c+time.time())
        return random.randint(1,10)
    
    def doUniqueRandom(sd,bg,ed):

        tmp=sd*sd-12
        random.seed(tmp)
        return random.randint(bg,ed)

    def getRandomSeed(string,key):

        length=len(string)
        num=0
        for i in range(length):
            code=ord(string[i])
            num+=code*(key*2-1)
        return num


except Exception as E:
    print("\033[31m ================函数定义处出现异常，程序停止运行！================ \033[0m")
    print(f"Error: {E} ")
    exit()

#############################################输入
try:
    nma=""
    rda=0
    nmb=""
    rdb=0
    nma=str(input("请输入名字1:  "))
    rda=getRandomSeed(nma,1)
    #print("<调试> "+nma+"的随机种子是："+str(rda))
    nmb=str(input("请输入名字2:  "))
    rdb=getRandomSeed(nmb,1)
    #print("<调试> "+nmb+"的随机种子是："+str(rdb))
except Exception as E:
    print("\033[31m================输入与制作随机种子处出现异常，程序停止运行！================\033[0m")
    print(f"Error:{E}")
    exit()

#############################################各数值初始化处
try:

    print("战斗开始中，请稍等......")
    time.sleep(1)

    tlfa=doUniqueRandom(rda,0,3)
    tlfb=doUniqueRandom(rdb,0,3)
    print("===天赋初始化完成===")
    time.sleep(0.5)
    print(nma+"的天赋为： "+tls[tlfa])
    time.sleep(0.1)
    print("效果："+tlexps[tlfa])
    time.sleep(0.5)
    print(nmb+"的天赋为： "+tls[tlfb])
    time.sleep(0.1)
    print("效果："+tlexps[tlfb])
    time.sleep(1)

    lfa=doUniqueRandom(rda,100,200)
    random.seed(rdb)
    lfb=doUniqueRandom(rdb,100,200)
    print("===血量初始化完成===")
    if tlfa==3:
        adda=random.randint(10,30)
        print(nma+"的初始血量为： "+str(lfa)+"+"+str(adda))
        lfa+=adda
    else:
        print(nma+"的初始血量为： "+str(lfa))
    time.sleep(0.5)
    if tlfb==3:
        addb=random.randint(10,30)
        print(nmb+"的初始血量为： "+str(lfb)+"+"+str(addb))
        lfb+=addb
    else:
        print(nmb+"的初始血量为： "+str(lfb))

    time.sleep(1)

    print("")
    start="==================战斗开始=================="
    print(f"\033[31m{start}\033[0m")
    print("")
except Exception as E:
    print("\033[31m================初始化处出现异常，程序停止运行！================\033[0m")
    print(f"Error:{E}")
    exit()

#############################################主体
try:
    for i in range(1000):

        time.sleep(1)
        tmplfa=lfa
        tmplfb=lfb
        out=""

        #随机技能与攻击力
        skla=doRandomChoice(rda,skls,cnt)
        cnt+=1
        if (skla=="须佐能乎" and xuzuoa==True) or (skla=="我眼即你眼" and zaiyana==True) or (skla=="无下限术式" and zaiyana==True):
            while not(skla!="须佐能乎" and skla!="我眼即你眼" and skla!="无下限术式"):
                skla=doRandomChoice(rda,skls,cnt)
                cnt+=1

        sklb=doRandomChoice(rdb,skls,cnt)
        cnt+=1
        if (sklb=="须佐能乎" and xuzuob==True) or (sklb=="我眼即你眼" and zaiyanb==True) or (sklb=="无下限术式" and zaiyanb==True):
            while not(sklb!="须佐能乎" and sklb!="我眼即你眼" and sklb!="无下限术式"):
                sklb=doRandomChoice(rdb,skls,cnt)
                cnt+=1

        atka=doRandint(rda,10,60,cnt)
        cnt+=1
        atkb=doRandint(rdb,10,60,cnt)
        cnt+=1

        print(" ")
        print("        =========第"+str(i+1)+"回合开始=========")

        #轮到A攻击的回合
        if skla=="须佐能乎":
            out=nma+"使用了"+skla+",下一次攻击必定暴击！"
            print(f"\033[35m{out}\033[0m")
            xuzuoa=True

        elif skla=="我眼即你眼":
            out=nma+"使用了"+skla+"给予了"+nmb+"一个致盲效果，他下回的攻击会被闪避！"
            print(f"\033[35m{out}\033[0m")
            zaiyana=True

        elif skla=="回复":
            out=nma+"使用了"+skla+"，恢复了"+str(atka)+"点血量"
            print(f"\033[32m{out}\033[0m")
            lfa+=atka
            totalTreatmenta+=atka

        elif skla=="无下限术式":
            out=nma+"使用了"+skla+"，下回"+nmb+"的攻对他无效！"
            print(f"\033[34m{out}\033[0m")
            wuxiana=True

        elif skla=="雷切":
            wuxianb=False
            zaiyanb=False
            if tlfa==0:
                out=nma+"使用了"+skla+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"+"+str(add)+"点伤害"
                print(f"\033[34m{out}\033[0m")
                add=doRandint(rda,1,10,time.time())
                atka+=add
            else:
                out=nma+"使用了"+skla+"，无视"+nmb+"的天赋，无法减伤或躲避!"+"打出了"+str(atka)+"点伤害"
                print(f"\033[34m{out}\033[0m")
            lfb-=atka
            print(nma+"受到了"+str(atka)+"点伤害")

        else:
            if tlfa==0:
                add=doRandint(rda,1,10,time.time())
                print(nma+"使用了"+skla+"，打出了"+str(atka)+"+"+str(add)+"点伤害")
                atka+=add
            else:
                print(nma+"使用了"+skla+"，打出了"+str(atka)+"点伤害")

            time.sleep(0.5)
            hdb=doRandomHide(rdb,cnt)
            cnt+=1

            if xuzuoa:
                if tlfb==2:
                    add=doRandint(rdb,5,20,time.time())
                    out="由于"+nma+"使用了须佐能乎，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                    print(f"\033[31m{out}\033[0m")
                    lfb-=atka*2+add
                else:
                    out="由于"+nma+"使用了须佐能乎，"+nmb+"直接受到了暴击，承受了"+str(atka*2)+"点伤害"
                    print(f"\033[31m{out}\033[0m")
                    lfb-=atka*2
                xuzuoa=False

            elif zaiyanb:
                out="由于"+nmb+"使用了我眼即你眼，"+nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
                print(f"\033[30m{out}\033[0m")
                lfb-=atka/2
                zaiyanb=False

            elif wuxianb:
                print("但是由于"+nmb+"使用了无下限术式，所以本次攻击不奏效！")
                wuxianb=False

            else:
                nbrdm=doRandint(time.time(),1,15,cnt)
                cnt+=1
                if nbrdm==7:
                    out=nmb+"直接反弹，使"+nma+"受到了"+str(atka-10)+"点伤害！"
                    print(f"\033[36m{out}\033[0m")

                elif 1<=rdb and 3>=rdb:
                    tri=random.randint(1,5)
                    if tlfb==1 and tri==3:
                        out=nmb+"灵巧地躲过了暴击，只承受了"+str(atka)+"点伤害"
                        print(f"\033[30m{out}\033[0m")
                        lfb-=atka
                    else:
                        if tlfb==2:
                            add=doRandint(rdb,5,20,time.time())
                            out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"-"+str(add)+"点伤害"
                            print(f"\033[31m{out}\033[0m")
                            lfb-=atka*2+add
                        else:
                            out=nmb+"躲闪不及，受到了暴击，承受了"+str(atka*2)+"点伤害"
                            print(f"\033[31m{out}\033[0m")
                            lfb-=atka*2

                elif 8<=rdb and 10>=rdb:
                    out=nmb+"闪避成功，只承受了"+str(atka/2)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfb-=atka/2

                else:
                    tri=random.randint(1,5)
                    if tlfb==1 and tri==3:
                        out=nmb+"灵巧地躲过了攻击，只承受了"+str(atka/2)+"点伤害"
                        print(f"\033[30m{out}\033[0m")
                        lfb-=atka/2
                    else:
                        print(nmb+"受到了"+str(atka)+"点伤害")
                        lfb-=atka

        time.sleep(1)

        #统计数据
        if(tmplfb-lfb>0):
            totalAttacka+=tmplfb-lfb
        if(tmplfa-lfa>0):
            totalAttackb+=tmplfa-lfa

        #判断是否有一方倒下
        if(lfa<=0):
            print(" ")
            print(" ")
            print(" ")
            print("==================战斗结束，"+nmb+"胜利！！==================")
            print("剩余血量："+str(lfb))
            break
        if(lfb<=0):
            print(" ")
            print(" ")
            print(" ")
            print("==================战斗结束，"+nma+"胜利！！==================")
            print(">>>剩余血量："+str(lfa))
            break

        #轮到B攻击的回合    
        if sklb=="须佐能乎":
            out=nmb+"使用了"+sklb+"，下一次攻击必定暴击！"
            print(f"\033[35m{out}\033[0m")
            xuzuob=True

        elif sklb=="我眼即你眼":
            out=nmb+"使用了"+sklb+"，给予了"+nma+"一个致盲效果，他下回的攻击会被闪避！"
            print(f"\033[35m{out}\033[0m")
            zaiyanb=True

        elif sklb=="回复":
            out=nmb+"使用了"+sklb+"，恢复了"+str(atkb)+"点血量"
            print(f"\033[32m{out}\033[0m")
            lfb+=atkb
            totalTreatmentb+=atkb

        elif sklb=="无下限术式":
            out=nmb+"使用了"+sklb+"，下回"+nma+"的攻对他无效！"
            print(f"\033[34m{out}\033[0m")
            wuxianb=True

        elif sklb=="雷切":
            wuxiana=False
            zaiyana=False
            if tlfb==0:
                out=nmb+"使用了"+sklb+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"+"+str(add)+"点伤害"
                print(f"\033[34m{out}\033[0m")
                add=doRandint(rdb,1,10,time.time())
                atkb+=add
            else:
                out=nmb+"使用了"+sklb+"，无视"+nma+"的任何天赋与防御，无法减伤或躲避!"+"打出了"+str(atkb)+"点伤害"
                print(f"\033[34m{out}\033[0m")
            lfa-=atkb
            print(nma+"受到了"+str(atkb)+"点伤害")

        else:
            if tlfb==0:
                add=doRandint(rda,1,10,time.time())
                print(nmb+"使用了"+sklb+"，打出了"+str(atkb)+"+"+str(add)+"点伤害")
                atkb+=add
            else:
                print(nmb+"使用了"+sklb+"，打出了"+str(atkb)+"点伤害")

            time.sleep(0.5)
            hda=doRandomHide(rda,cnt)
            cnt+=1

            if xuzuob:
                if tlfa==2:
                    add=doRandint(rdb,5,20,time.time())
                    out="由于"+nmb+"使用了须佐能乎，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                    print(f"\033[31m{out}\033[0m")
                    lfa-=atkb*2+add
                else:
                    out="由于"+nmb+"使用了须佐能乎，"+nma+"直接受到了暴击，承受了"+str(atkb*2)+"点伤害"
                    print(f"\033[31m{out}\033[0m")
                    lfa-=atkb*2

                xuzuob=False

            elif zaiyana:
                out="由于"+nma+"使用了我眼即你眼，"+nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
                print(f"\033[30m{out}\033[0m")
                lfa-=atkb/2
                zaiyana=False

            elif wuxiana:
                print("但是由于"+nma+"使用了无下限术式，所以本次攻击不奏效！")
                wuxiana=False

            else:
                nbrdm=doRandint(time.time(),1,15,cnt)
                cnt+=7
                if nbrdm==20:
                    out=nma+"直接反弹，使"+nmb+"受到了"+str(atkb-10)+"点伤害！"
                    print(f"\033[36m{out}\033[0m")

                elif 1<=rda and 3>=rda:
                    tri=random.randint(1,5)
                    if tlfa==1 and tri==3:
                        out=nma+"灵巧地躲过了暴击，只承受了"+str(atkb)+"点伤害"
                        print(f"\033[30m{out}\033[0m")
                        lfa-=atkb
                    else:

                        if tlfa==2:
                            add=doRandint(rda,5,20,time.time())
                            out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"-"+str(add)+"点伤害"
                            print(f"\033[31m{out}\033[0m")
                            lfa-=atkb*2+add
                        else:
                            out=nma+"躲闪不及，受到了暴击，承受了"+str(atkb*2)+"点伤害"
                            print(f"\033[31m{out}\033[0m")
                            lfa-=atkb*2

                elif 7<=rda and 10>=rda:
                    out=nma+"闪避成功，只承受了"+str(atkb/2)+"点伤害"
                    print(f"\033[30m{out}\033[0m")
                    lfa-=atkb/2

                else:
                    tri=random.randint(1,5)
                    if tlfa==1 and tri==3:
                        out=nma+"灵巧地躲过了攻击，只承受了"+str(atkb/2)+"点伤害"
                        print(f"\033[30m{out}\033[0m")
                        lfa-=atkb/2
                    else:
                        print(nma+"受到了"+str(atkb)+"点伤害")
                        lfa-=atkb

        time.sleep(1)

        #统计数据
        if(tmplfb-lfb>0):
            totalAttacka+=tmplfb-lfb
        if(tmplfa-lfa>0):
            totalAttackb+=tmplfa-lfa

        #恩赐与诅咒判定
        if((i+1)%5==0): #恩赐
            add=doRandint(time.time(),20,50,cnt)
            cnt+=1
            nid=doRandint(time.time(),0,1,cnt)
            cnt+=1
            if bool(nid):
                out="本回合触发了天使的恩赐,"+nma+"血量回复"+str(add)+"点"
                print(f"\033[32m{out}\033[0m")
                lfa+=add
            else:
                out="本回合触发了天使的恩赐,"+nmb+"血量回复"+str(add)+"点"
                print(f"\033[32m{out}\033[0m")
                lfb+=add

        if((i+1)%7==0): #诅咒
            add=doRandint(time.time(),20,50,cnt)
            cnt+=1
            nid=doRandint(time.time(),0,1,cnt)
            cnt+=1
            if bool(nid):
                out="本回合触发了恶魔的诅咒,"+nma+"血量扣除"+str(add)+"点"
                print(f"\033[31m{out}\033[0m")
                lfa-=add
            else:
                out="本回合触发了恶魔的诅咒,"+nmb+"血量扣除"+str(add)+"点"
                print(f"\033[31m{out}\033[0m")
                lfb-=add


        #结算本回合
        print("        =========第"+str(i+1)+"回合结束=========")
        print(" ")
        time.sleep(0.5)
        print(nma+">>>剩余血量："+str(lfa))
        print(nmb+">>>剩余血量："+str(lfb))

        #判断是否有一方倒下
        if(lfa<=0):
            print(" ")
            print(" ")
            print(" ")
            out="==================战斗结束，"+nmb+"胜利！！=================="
            print(f"\033[33m{out}\033[0m")
            print("                  剩余血量："+str(lfb))
            break
        if(lfb<=0):
            print(" ")
            print(" ")
            print(" ")
            out="==================战斗结束，"+nma+"胜利！！=================="
            print(f"\033[33m{out}\033[0m")
            print("                  剩余血量："+str(lfa))
            break

except Exception as E:
    print("\033[31m================对战处出现异常，程序停止运行！================\033[0m")
    print(f"Error:{E}")
    exit()

#############################################结算画面
try:
    print(" ")
    print("\033[36m结算中......\033[0m")
    print(" ")
    time.sleep(3)
    print(nma+"总治疗量："+str(totalTreatmenta))
    print(nmb+"总治疗量："+str(totalTreatmentb))
    print(nma+"总造成伤害："+str(totalAttacka))
    print(nmb+"总造成伤害："+str(totalAttackb))
    print("总回合数:"+str(i+1))
    print(" ")
except Exception as E:
    print("\033[31m================结算处出现异常，程序停止运行！================\033[0m")
    print(f"Error:{E}")
    exit()
